/* SPDX-License-Identifier: GPL-2.0 */

/**
 * Copyright (C) 2025 Huawei Technologies Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, see <https://www.gnu.org/licenses/>.
 *
 * @file cman_drv.h
 * @brief Kunpeng Cache Management kernel driver definitions
 */

#ifndef CMAN_DRV_H
#define CMAN_DRV_H

MODULE_LICENSE("GPL");

/**
 * A define for driver version number
 */
#define CMAN_DRV_VER	1008

#define DEVICE_NAME		"Cache Management Framework control device"
#define CMAN_MAGIC		'x'
#define DEVICE_COUNT	1

/** @struct l2_partition_ioctl_args
 *  @brief  Struct containing L2 I/D partition arguments passed from the userspace.
 *  @var    l2_partition_ioctl_args::cpu
 *  Member 'cpu' contains cpu ID to operate on.
 *  @var    l2_partition_ioctl_args::l2_partition_dmask
 *  Member 'l2_partition_dmask' stores the mask to be set for data requests on current CPU.
 *  @var    l2_partition_ioctl_args::l2_partition_imask
 *  Member 'l2_partition_imask' stores the mask to be set for instructions on current CPU.
 */
#pragma pack(push, 8)
struct l2_partition_ioctl_args {
	s32 cpu;
	u64 l2_partition_dmask;
	u64 l2_partition_imask;
};
#pragma pack(pop)

/** @struct hw_info_ioctl_args
 *  @brief  Struct containing hardware information to be passed to the userspace.
 *  Member 'l2_segment_size' contains size of L2 I/D partition granularity.
 *  @var    hw_info_ioctl_args::l2_capacity
 *  Member 'l2_capacity' contains L2 cache capacity of a single CPU.
 */
#pragma pack(push, 8)
struct hw_info_ioctl_args {
	s64 l2_segment_size;
	u64 l2_capacity;
};
#pragma pack(pop)

#define CMAN_L2_PART_GET			_IOWR(CMAN_MAGIC, 3, struct l2_partition_ioctl_args)
#define CMAN_L2_PART_SET			_IOW(CMAN_MAGIC, 4, struct l2_partition_ioctl_args)
#define CMAN_VERSION				_IOR(CMAN_MAGIC, 6, s32)
#define CMAN_HW_INFO				_IOR(CMAN_MAGIC, 12, struct hw_info_ioctl_args)
#define CMAN_RESET_L2_PART			_IOW(CMAN_MAGIC, 14, s32)

#endif /* CMAN_DRV_H */
